using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using Entites;
using Utility;

namespace BUS
{
   public class DonHangBUS
    {
       
         public static void Insert(DonHang dh)
        {
            DonHangDAL dhDAL = new DonHangDAL();
            dhDAL.Insert(dh);
        }
        public static void Update(DonHang dh)
        {
            DonHangDAL dhDAL = new DonHangDAL();
            dhDAL.Update(dh);
        }
        public static void Delete(int iD)
        {
            DonHangDAL dhDAL = new DonHangDAL();
            dhDAL.Delete(iD);
        }
        public static tbDonHangCollection Get(string where,
            int pageindex,
            int pagesize,
            string orderby,
            string orderdirection,
            out int total)
        {
            DonHangDAL dhDAL = new DonHangDAL();
            return dhDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbDonHangCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            DonHangDAL dhDAL = new DonHangDAL();
            return dhDAL.Get(cri.Criter, 0, 0, tbDonHangColumns.MaDH.ToString(), OrderDirection.ASC.ToString(), out total);
        }
       public static DonHang GetByID(int iD)
       {
           int total = 0;
           Criteria cri = new Criteria();
           cri.add(Condition.AND, tbDonHangColumns.MaDH.ToString(), Condition.EQUAL, iD);
           DonHangDAL dhDAL = new DonHangDAL();
           tbDonHangCollection donhangcollection = dhDAL.Get(cri.Criter,
                 0, 0, tbDonHangColumns.MaDH.ToString(), OrderDirection.ASC.ToString(), out total);
           if (donhangcollection.Count > 0)
               return donhangcollection[0];
           return null;
       }
      
        public static tbDonHangCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            DonHangDAL dhDAL = new DonHangDAL();
            return dhDAL.Get(cri.Criter, 1, number,
             tbDonHangColumns.MaDH.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbDonHangCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            DonHangDAL dhDAL = new DonHangDAL();
            return dhDAL.Get(cri.Criter, 1, number,
               tbDonHangColumns.MaDH.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
    
}
